package com.alison.scala

import org.apache.spark.{SparkConf, SparkContext}

object WordCountHdfs {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      //本地模式运行
      .setMaster("local[4]")
      .setAppName("wordcount")
    val sc = new SparkContext(conf)
    //读取hdfs文件
    val fileRDD=sc.textFile("hdfs://localhost:8020/testdatas/input/words.txt")
    //读取本地文件
    //val fileRDD=sc.textFile("file:\\C:\\WorkSpaces\\testdatas\\input\\words.txt")
    val wordRDD=fileRDD.flatMap(_.split(" "))
    val groupRDD = wordRDD.map((_,1)).reduceByKey(_+_)
    val wordCountArray = groupRDD.collect()
    println(wordCountArray.mkString(","))
  }

}
